//
//  WsbsMainViewController.m
//  上海杨浦
//
//  Created by FrankChen on 13-10-28.
//  Copyright (c) 2013年 FrankChen. All rights reserved.
//

#import "WsbsMainViewController.h"
#import "YpywViewController.h"
#import "WsbsViewController.h"
#import "AppDelegate.h"

#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

#define IOS_VERSION_7_OR_ABOVE (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)? (YES):(NO))


@implementation WsbsMainViewController
@synthesize Button1;
@synthesize Button2;
@synthesize Button3;
@synthesize ScrollView;
@synthesize Btn_back;
@synthesize imageView1;
@synthesize imageViewSecTop;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    if (iPhone5) {
        diff=88;
    }
    else{
        diff=0;
    }
    if (IOS_VERSION_7_OR_ABOVE) {
        diff=diff+20;
    }

    [self AddImageView];
    [self AddTopButton];
    [self AddScrollView:650];
    [self fenlei1AddBtns];
    flag=1;
}


-(void)AddImageView{
    UIImageView *imageView=[[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 420+diff)]autorelease];
    [imageView setImage:[UIImage imageNamed:@"banshi_bg.png"]];
    [self.view addSubview:imageView];
}

-(void)AddScrollView:(int )maxHeight{
    UIScrollView *scrollView=[[[UIScrollView alloc]initWithFrame:CGRectMake(25, 280+diff/1.7, 270, 411)]autorelease];
    [scrollView setContentSize:CGSizeMake(270, maxHeight)];
    [scrollView setBackgroundColor:[UIColor clearColor  ]];
    
    ScrollView=scrollView;
}

-(void)AddTopButton{
    CGRect frame1=CGRectMake(30, 190+diff/2, 80, 80);
    CGRect frame2=CGRectMake(120, 190+diff/2, 80, 80);
    CGRect frame3=CGRectMake(210, 190+diff/2, 80, 80);
    
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn1 setImage:[UIImage imageNamed:@"banshi_fenlei1.png"] forState:UIControlStateNormal];
    btn1.frame = frame1;
    //[btn1 addTarget:self action:@selector(bigButtonClicked) forControlEvents:UIControlEventTouchDown];
    [btn1 setTag:401];
    [btn1 addTarget:self action:@selector(bigButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    Button1=btn1;
    
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn2 setImage:[UIImage imageNamed:@"banshi_fenlei2no.png"] forState:UIControlStateNormal];
    btn2.frame = frame2;
    //[btn2 addTarget:self action:@selector(bigButtonClicked) forControlEvents:UIControlEventTouchDown];
    [btn2 setTag:402];
    [btn2 addTarget:self action:@selector(bigButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    Button2=btn2;
    
    UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn3 setImage:[UIImage imageNamed:@"banshi_fenlei3no.png"] forState:UIControlStateNormal];
    btn3.frame = frame3;
    //[btn3 addTarget:self action:@selector(bigButtonClicked) forControlEvents:UIControlEventTouchDown];
    [btn3 setTag:403];
    [btn3 addTarget:self action:@selector(bigButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    Button3=btn3;
    
    [self.view addSubview:btn1];
    [self.view addSubview:btn2];
    [self.view addSubview:btn3];
}

-(IBAction) bigButtonClicked:(id)sender {
    UIButton *currentBtn=(UIButton *)sender;
    switch (currentBtn.tag) {
        case 401:
        {
            [Button1 setImage:[UIImage imageNamed:@"banshi_fenlei1.png"] forState:UIControlStateNormal];
            [Button2 setImage:[UIImage imageNamed:@"banshi_fenlei2no.png"] forState:UIControlStateNormal];
            [Button3 setImage:[UIImage imageNamed:@"banshi_fenlei3no.png"] forState:UIControlStateNormal];
            [ScrollView removeFromSuperview];
            [self AddScrollView:650];
            [self fenlei1AddBtns];
            flag=1;
            
        }
        break;
            
        case 402:
        {
            [Button1 setImage:[UIImage imageNamed:@"banshi_fenlei1no.png"] forState:UIControlStateNormal];
            [Button2 setImage:[UIImage imageNamed:@"banshi_fenlei2.png"] forState:UIControlStateNormal];
            [Button3 setImage:[UIImage imageNamed:@"banshi_fenlei3no.png"] forState:UIControlStateNormal];
            [ScrollView removeFromSuperview];
            [self AddScrollView:820];
            [self fenlei2AddBtns];
            flag=2;
        }
        break;
            
        case 403:
        {
            [Button1 setImage:[UIImage imageNamed:@"banshi_fenlei1no.png"] forState:UIControlStateNormal];
            [Button2 setImage:[UIImage imageNamed:@"banshi_fenlei2no.png"] forState:UIControlStateNormal];
            [Button3 setImage:[UIImage imageNamed:@"banshi_fenlei3.png"] forState:UIControlStateNormal];
            [ScrollView removeFromSuperview];
            [self AddScrollView:550];
            [self fenlei3AddBtns];
            flag=3;
        }
        break;
    }
}



-(void)fenlei1AddBtns{
    UILabel *label=[[[UILabel alloc]initWithFrame:CGRectMake(8, -5, 270, 30)]autorelease];
    UIFont *font=[UIFont fontWithName:@"FZHTJW--GB1-0" size:19.0f];
    [label setFont:font];
    [label setBackgroundColor:[UIColor clearColor]];
    [label setNumberOfLines:2];
    [label setTextColor:[UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1]];
    [label setText:@"以下按生命周期分类"];
    [label setTextAlignment:NSTextAlignmentLeft];
    [ScrollView addSubview:label];
    
    [self AddBtnToScrollView:8 :33 :6062 :@"生育"];
    [self AddBtnToScrollView:144 :33 :6063 :@"户籍"];
    [self AddBtnToScrollView:8 :66 :6064 :@"教育"];
    [self AddBtnToScrollView:144 :66 :6065 :@"兵役"];
    [self AddBtnToScrollView:8 :99 :6066 :@"就业"];
    [self AddBtnToScrollView:144 :99 :6067 :@"婚姻"];
    [self AddBtnToScrollView:8 :132 :6068 :@"医疗"];
    [self AddBtnToScrollView:144 :132 :6069 :@"居住"];
    [self AddBtnToScrollView:8 :165 :6070 :@"交通"];
    [self AddBtnToScrollView:144 :165 :6071 :@"福利"];
    [self AddBtnToScrollView:8 :197 :6072 :@"社保"];
    [self AddBtnToScrollView:144 :197 :6073 :@"优抚"];
    [self AddBtnToScrollView:8 :230 :6074 :@"工商"];
    [self AddBtnToScrollView:144 :230 :6075 :@"税务"];
    [self AddBtnToScrollView:8 :263 :6076 :@"公安"];
    [self AddBtnToScrollView:144 :263 :6077 :@"法律"];
    [self AddBtnToScrollView:8 :296 :6078 :@"出境"];
    [self AddBtnToScrollView:144 :296 :6079 :@"宗教"];
    [self AddBtnToScrollView:8 :329 :6080 :@"殡葬"];
    [self AddBtnToScrollView:144 :329 :6081 :@"其他"];
    
    [self.view addSubview:ScrollView];
}


-(void)fenlei2AddBtns{
    UILabel *label=[[[UILabel alloc]initWithFrame:CGRectMake(8, -5, 270, 30)]autorelease];
    UIFont *font=[UIFont fontWithName:@"FZHTJW--GB1-0" size:19.0f];
    [label setFont:font];
    [label setBackgroundColor:[UIColor clearColor]];
    [label setNumberOfLines:2];
    [label setTextColor:[UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1]];
    [label setText:@"以下按部门分类"];
    [label setTextAlignment:NSTextAlignmentLeft];
    [ScrollView addSubview:label];
    
    [self AddBtnToScrollView:8 :33 :5998 :@"教育局"];
    [self AddBtnToScrollView:144 :33 :5999 :@"残联"];
    [self AddBtnToScrollView:8 :66 :6021 :@"工商局"];
    [self AddBtnToScrollView:144 :66 :6022 :@"计生委"];
    [self AddBtnToScrollView:8 :99 :6023 :@"房管局"];
    [self AddBtnToScrollView:144 :99 :6024 :@"食药监"];
    [self AddBtnToScrollView:8 :132 :6025 :@"旅游局"];
    [self AddBtnToScrollView:144 :132 :6027 :@"科委"];
    [self AddBtnToScrollView:8 :165 :6029 :@"公安局"];
    [self AddBtnToScrollView:144 :165 :6030 :@"国资委"];
    [self AddBtnToScrollView:8 :197 :6031 :@"民政局"];
    [self AddBtnToScrollView:144 :197 :6032 :@"司法局"];
    [self AddBtnToScrollView:8 :230 :6033 :@"发改委"];
    [self AddBtnToScrollView:144 :230 :6034 :@"商务委"];
    [self AddBtnToScrollView:8 :263 :6035 :@"档案局"];
    [self AddBtnToScrollView:144 :263 :6036 :@"质监局"];
    [self AddBtnToScrollView:8 :296 :6037 :@"组织部"];
    [self AddBtnToScrollView:144 :296 :6038 :@"卫生局"];
    [self AddBtnToScrollView:8 :329 :6039 :@"安监局"];
    [self AddBtnToScrollView:144 :329 :6040 :@"绿化市容局"];
    [self AddBtnToScrollView:8 :362 :6041 :@"民防办"];
    [self AddBtnToScrollView:144 :362 :6042 :@"爱卫办"];
    [self AddBtnToScrollView:8 :395 :6044 :@"环保局"];
    [self AddBtnToScrollView:144 :395 :6045 :@"建交委"];
     [self AddBtnToScrollView:8 :428 :6046 :@"体育局"];
     [self AddBtnToScrollView:144 :428 :6047 :@"民宗办"];
    [self AddBtnToScrollView:8 :461 :6048 :@"文化局"];
    [self AddBtnToScrollView:144 :461 :6049 :@"总工会"];
    [self AddBtnToScrollView:8 :494 :6050 :@"街道(镇)"];
    
    [self.view addSubview:ScrollView];
}

-(void)fenlei3AddBtns{
    UILabel *label=[[[UILabel alloc]initWithFrame:CGRectMake(8, -5, 270, 30)]autorelease];
    UIFont *font=[UIFont fontWithName:@"FZHTJW--GB1-0" size:19.0f];
    [label setFont:font];
    [label setBackgroundColor:[UIColor clearColor]];
    [label setNumberOfLines:2];
    [label setTextColor:[UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1]];
    [label setText:@"以下按服务对象分类"];
    [label setTextAlignment:NSTextAlignmentLeft];
    [ScrollView addSubview:label];
    
    [self AddBtnToScrollView:8 :33 :6083 :@"妇女"];
    [self AddBtnToScrollView:144 :33 :6084 :@"儿童"];
    [self AddBtnToScrollView:8 :66 :6085 :@"老人"];
    [self AddBtnToScrollView:144 :66 :6086 :@"残疾人"];
    [self AddBtnToScrollView:8 :99 :6087 :@"特困人员"];
    [self AddBtnToScrollView:144 :99 :6088 :@"优抚对象"];
    [self AddBtnToScrollView:8 :132 :6089 :@"港澳台同胞"];
    [self AddBtnToScrollView:144 :132 :6090 :@"海外侨胞"];
    [self AddBtnToScrollView:8 :165 :6091 :@"留学归国"];
    [self AddBtnToScrollView:144 :165 :6092 :@"外国人"];
    [self AddBtnToScrollView:8 :197 :6093 :@"学生"];
    [self AddBtnToScrollView:144 :197 :6094 :@"退休人员"];
    [self AddBtnToScrollView:8 :230 :6095 :@"其他"];

    
    [self.view addSubview:ScrollView];
}

-(void)AddBtnToScrollView:(int)X_zuobiao :(int)Y_zuobiao :(int)Tag :(NSString *)Name{
    CGRect frame=CGRectMake(X_zuobiao, Y_zuobiao, 118, 29);
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setBackgroundImage:[UIImage imageNamed:@"banshi_btn"] forState:UIControlStateNormal];
    btn.frame = frame;
    [btn setTag:Tag];
    [btn setTitle:Name forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(fenlei1ButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    [ScrollView addSubview:btn];
}

-(IBAction) fenlei1ButtonClicked:(id)sender {
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
    btn= (UIButton *)sender;
    //NSString *tag=[NSString stringWithFormat:@"%d",btn.tag];
    [self refectLANMUName:btn.tag];
    
    WsbsViewController *wsbs=[[WsbsViewController alloc]init];
    


    
    
    
    //NSString *sdf=appdele.WEBURL;
    
    viewc1=wsbs;

    [self.view addSubview:wsbs.view];
    
    [self AddTopImageView];
    [self AddSedTopImageView:btn.currentTitle];
}

-(void)refectLANMUName:(int *) _tag{
    AppDelegate *appdele=(AppDelegate*)[[UIApplication sharedApplication]delegate];
    appdele.LANMUName=@"";
    NSUInteger tag=_tag;
    switch (tag) {
        case 5998:
            appdele.LANMUName=@"jiaoyuju";
            break;
        case 5999:
            appdele.LANMUName=@"canlian";
            break;
        case 6021:
            appdele.LANMUName=@"gongshangju";
            break;
        case 6022:
            appdele.LANMUName=@"jishengwei";
            break;
        case 6023:
            appdele.LANMUName=@"fangguanjv";
            break;
        case 6024:
            appdele.LANMUName=@"shiyaojian";
            break;
        case 6025:
            appdele.LANMUName=@"lvyouju";
            break;
        case 6027:
            appdele.LANMUName=@"kewei";
            break;
        case 6029:
            appdele.LANMUName=@"gonganju";
            break;
        case 6030:
            appdele.LANMUName=@"guoziwei";
            break;
        case 6031:
            appdele.LANMUName=@"minzhengju";
            break;
        case 6032:
            appdele.LANMUName=@"sifaju";
            break;
        case 6033:
            appdele.LANMUName=@"fagaiwei";
            break;
        case 6034:
            appdele.LANMUName=@"shangwuju";
            break;
        case 6035:
            appdele.LANMUName=@"danganju";
            break;
        case 6036:
            appdele.LANMUName=@"zhijianju";
            break;
        case 6037:
            appdele.LANMUName=@"zuzhibu";
            break;
        case 6038:
            appdele.LANMUName=@"weishengju";
            break;
        case 6039:
            appdele.LANMUName=@"anjianju";
            break;
        case 6040:
            appdele.LANMUName=@"lvhuashirongju";
            break;
        case 6041:
            appdele.LANMUName=@"minfangban";
            break;
        case 6042:
            appdele.LANMUName=@"aiweiban";
            break;
        case 6044:
            appdele.LANMUName=@"huanbaoju";
            break;
        case 6045:
            appdele.LANMUName=@"jianjiaowei";
            break;
        case 6046:
            appdele.LANMUName=@"tiyuju";
            break;
        case 6047:
            appdele.LANMUName=@"minzongban";
            break;
        case 6048:
            appdele.LANMUName=@"wenhuaju";
            break;
        case 6049:
            appdele.LANMUName=@"zonggonghui";
            break;
        case 6050:
            appdele.LANMUName=@"jiedaozhen";
            break;
            
        case 6062:
            appdele.LANMUName=@"shengyu";
            break;
        case 6063:
            appdele.LANMUName=@"huji";
            break;
        case 6064:
            appdele.LANMUName=@"jiaoyu";
            break;
        case 6065:
            appdele.LANMUName=@"bingyi";
            break;
        case 6066:
            appdele.LANMUName=@"jiuye";
            break;
        case 6067:
            appdele.LANMUName=@"hunyin";
            break;
        case 6068:
            appdele.LANMUName=@"yiliao";
            break;
        case 6069:
            appdele.LANMUName=@"juzhu";
            break;
        case 6070:
            appdele.LANMUName=@"jiaotong";
            break;
        case 6071:
            appdele.LANMUName=@"fuli";
            break;
        case 6072:
            appdele.LANMUName=@"shebao";
            break;
        case 6073:
            appdele.LANMUName=@"fuyou";
            break;
        case 6074:
            appdele.LANMUName=@"gongshang";
            break;
        case 6075:
            appdele.LANMUName=@"shuiwu";
            break;
        case 6076:
            appdele.LANMUName=@"gongan";
            break;
        case 6077:
            appdele.LANMUName=@"falv";
            break;
        case 6078:
            appdele.LANMUName=@"chujing";
            break;
        case 6079:
            appdele.LANMUName=@"zongjiao";
            break;
        case 6080:
            appdele.LANMUName=@"bingzang";
            break;
        case 6081:
            appdele.LANMUName=@"qita";
            break;
            
        case 6083:
            appdele.LANMUName=@"funv";
            break;

        case 6084:
            appdele.LANMUName=@"ertong";
            break;

        case 6085:
            appdele.LANMUName=@"laoren";
            break;

        case 6086:
            appdele.LANMUName=@"canjiren";
            break;

        case 6087:
            appdele.LANMUName=@"tekunrenyuan";
            break;

        case 6088:
            appdele.LANMUName=@"youfuduixiang";
            break;

        case 6089:
            appdele.LANMUName=@"gangaotaitongbao";
            break;

        case 6090:
            appdele.LANMUName=@"haiwaiqiaobao";
            break;

        case 6091:
            appdele.LANMUName=@"liuxueguiguo";
            break;

        case 6092:
            appdele.LANMUName=@"waiguoren";
            break;

        case 6093:
            appdele.LANMUName=@"xuesheng";
            break;

        case 6094:
            appdele.LANMUName=@"tuixiurenyuan";
            break;

        case 60975:
            appdele.LANMUName=@"qita2";
            break;

            
    }
    
    
}


-(void) AddTopImageView{
    int plus=0;
    if (!iPhone5) {
        plus=30;
    }
    imageView1=[[UIImageView alloc] initWithFrame:CGRectMake(0, 57+diff/1.7+30, 320, 30)];
    [imageView1 setBackgroundColor:[UIColor blueColor]];
    [self.view addSubview:imageView1];
    [self AddLabel];
    [self AddBtn_back];
}

-(void) AddSedTopImageView:(NSString *)name{
    int plus=0;
    if (!iPhone5) {
        plus=30;
    }
    
    imageViewSecTop=[[UIImageView alloc] initWithFrame:CGRectMake(0, 87+diff/1.7+30, 320, 30)];
    [imageViewSecTop setImage:[UIImage imageNamed:@"strip_s.png"]];
    
    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0, 1, 320, 28)];
    UIFont *font=[UIFont fontWithName:@"FZHTJW--GB1-0" size:18.0f];
    [label setFont:font];
    [label setBackgroundColor:[UIColor clearColor]];
    [label setTextColor:[UIColor whiteColor]];
    [label setTextAlignment:UITextAlignmentCenter];
    [label setText:name];

    [imageViewSecTop addSubview:label];
    
    [self.view addSubview:imageViewSecTop];
}

-(void) AddLabel{
    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(0, 1, 320, 28)];
    UIFont *font=[UIFont fontWithName:@"FZHTJW--GB1-0" size:18.0f];
    [label setFont:font];
    [label setBackgroundColor:[UIColor blueColor]];
    [label setTextColor:[UIColor whiteColor]];
    [label setTextAlignment:UITextAlignmentCenter];
    switch (flag) {
        case 1:{
            [label setText:@"生命周期分类"];
            break;}
        case 2:{
            [label setText:@"部门分类"];
            break;}
        case 3:{
            [label setText:@"服务对象分类"];
            break;}
    }
    [imageView1 addSubview:label];
}

-(void)AddBtn_back{
    int plus=0;
    if (!iPhone5) {
        plus=30;
    }
    CGRect frame=CGRectMake(21, 57+diff/1.7+30, 72, 29);
    UIButton *btn_back=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn_back setImage:[UIImage imageNamed:@"btn_back.png"] forState:UIControlStateNormal];
    btn_back.frame=frame;
    [btn_back addTarget:self action:@selector(Btn_back_Clicked) forControlEvents:UIControlEventTouchUpInside];
    [[self view]addSubview:btn_back];
    Btn_back=btn_back;
}

-(void)Btn_back_Clicked{
    

    [Btn_back removeFromSuperview];
    [imageView1 removeFromSuperview];
    [imageViewSecTop removeFromSuperview];
    [viewc1.view removeFromSuperview];

}

@end

















































